let canvas = document.getElementById("imgPreview") as HTMLCanvasElement;
let wsJPG = new WebSocket(`ws://127.0.0.1:3602/preview/JPG`);
let drawContext = canvas.getContext("2d");
wsJPG.onopen = () => {
  console.log("已连接到ws后端");
}
wsJPG.onclose = () => {
  console.log("断开ws后端");
}
wsJPG.onmessage = msg => {
  let newFrame: Blob = msg.data;
  Promise.all([createImageBitmap(newFrame)]).then(newImage => {
    drawContext.drawImage(newImage[0], 0, 0, canvas.width, canvas.height);
  }).catch(reason => {
    console.log(reason);
  });
}
